<?php
/**
 * 会员提现逻辑层
 * @author maniac
 */
namespace app\common\logic;

use app\common\model\Members AS MembersModel;
use app\facade\UserLogs;

class MemberCash extends Base
{
    /**
     * 列表页修改状态
     * @param  array $data 请求的信息
     */
    public function status($data)
    {
        $model  = $this->getModel();
        $update = $this->statusAttach($data);
        $model::update($update);
        if ($data['value'] == 2) {
            $info = $model::field('userid,money')->where('id', $data['id'])->find();
            $member = MembersModel::field('id,profit')->where('id', $info['userid'])->find();
            $member->profit += $info['money'];
            $member->save();
        }
        UserLogs::insertLog(['title' => '修改'.(new $model)->tableName.'状态', 'content' => "id={$data['id']}"]);
        return true;
    }
    
    /**
     * 修改状态附件
     * @param  array $data 请求的信息
     */
    public function statusAttach($data)
    {
        return [
            'id'         => $data['id'],
            $data['key'] => $data['value'],
            'exam_time'  => time(),
        ];
    }
}
